<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <el-form-item label="用户" prop="userId">
        <el-select v-model="queryParams.userId" placeholder="请选择用户" clearable size="small">
          <el-option
            v-for="user in userList"
            :key="user.userId"
            :label="user.nickName"
            :value="user.userId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="traceNo">
        <el-input
          v-model="queryParams.traceNo"
          placeholder="请输入订单流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="业务类型(1：商品订购)" prop="businessType">
        <el-select v-model="queryParams.businessType" placeholder="请选择业务类型(1：商品订购)" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="支付单号" prop="payNo">
        <el-input
          v-model="queryParams.payNo"
          placeholder="请输入支付单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间" prop="payTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.payTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择支付时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="收货人姓名" prop="consigneeName">
        <el-input
          v-model="queryParams.consigneeName"
          placeholder="请输入收货人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货人手机号" prop="consigneeMobile">
        <el-input
          v-model="queryParams.consigneeMobile"
          placeholder="请输入收货人手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="业务状态" prop="businessStatus">
        <el-select v-model="queryParams.businessStatus" placeholder="请选择业务状态" clearable size="small">
          <el-option
            v-for="dict in businessStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="物流公司信息" prop="logisticsCompany">
        <el-input
          v-model="queryParams.logisticsCompany"
          placeholder="请输入物流公司信息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物流单号" prop="logisticsNumber">
        <el-input
          v-model="queryParams.logisticsNumber"
          placeholder="请输入物流单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="发货时间" prop="shipTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.shipTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择发货时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="配送方式" prop="freightType">
        <el-select v-model="queryParams.freightType" placeholder="请选择配送方式" clearable size="small">
          <el-option
            v-for="dict in freightTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="提货码" prop="fetchCode">
        <el-input
          v-model="queryParams.fetchCode"
          placeholder="请输入提货码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="销售信息(销售团长手机号，姓名)" prop="saleInfo">
        <el-input
          v-model="queryParams.saleInfo"
          placeholder="请输入销售信息(销售团长手机号，姓名)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提货信息" prop="takeInfo">
        <el-input
          v-model="queryParams.takeInfo"
          placeholder="请输入提货信息(提货店长手机号，姓名)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:order:export']"
        >导出</el-button>
      </el-col>
    </el-row>-->

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="orderId" />
      <el-table-column label="用户id" align="center" prop="userId" />-->
      <el-table-column label="订单号" align="center" prop="traceNo" :show-overflow-tooltip="true" />
      <!--<el-table-column label="业务类型(1：商品订购)" align="center" prop="businessType" />
      <el-table-column label="商品总费用" align="center" prop="goodsPrice" />
      <el-table-column label="配送费用" align="center" prop="freightPrice" />
      <el-table-column label="优惠券减免" align="center" prop="couponPrice" />
      <el-table-column label="用户积分减免" align="center" prop="integralPrice" />
      <el-table-column label="团购优惠价减免" align="center" prop="grouponPrice" />-->
      <el-table-column label="订单金额" align="center" prop="orderPrice" />
      <el-table-column label="实付金额" align="center" prop="amount" />
      <!--<el-table-column label="支付方式" align="center" prop="payType" />
      <el-table-column label="支付账户" align="center" prop="payAccount" />
      <el-table-column label="支付单号" align="center" prop="payNo" />-->
      <el-table-column label="业务状态" align="center" prop="businessStatus">
        <template slot-scope="scope">
          <el-tag v-for="dict in businessStatusOptions" v-if="dict.dictValue == scope.row.businessStatus">{{ dict.dictLabel }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="收货人姓名" align="center" prop="consigneeName" />
      <el-table-column label="收货人手机号" align="center" prop="consigneeMobile" />
      <el-table-column label="省份" align="center" prop="consigneeProvince" />
      <el-table-column label="城市" align="center" prop="consigneeCity" />
      <el-table-column label="收货地址所在区" align="center" prop="consigneeArea" />
      <el-table-column label="详细地址" align="center" prop="consigneeAddress" />-->
      <!--<el-table-column label="买家留言" align="center" prop="message" />
      <el-table-column label="备注(退款说明信息等)" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="物流公司信息" align="center" prop="logisticsCompany" />
      <el-table-column label="物流单号" align="center" prop="logisticsNumber" />-->
      <el-table-column label="发货时间" align="center" prop="shipTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shipTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="配送方式" align="center" prop="freightType" :formatter="freightTypeFormat" />
      <el-table-column label="推广用户" align="center" prop="shareUserId" />
      <el-table-column label="提货码" align="center" prop="fetchCode" />
      <el-table-column label="销售信息(销售团长手机号，姓名)" align="center" prop="saleInfo" />
      <el-table-column label="提货信息(提货店长手机号，姓名)" align="center" prop="takeInfo" />
      <el-table-column label="提货门店地址" align="center" prop="takeAddress" />
      <el-table-column label="是否已读(0：否、1：是),默认0" align="center" prop="isRead" />
      <el-table-column label="退款来源，当business_status为9时不为空" align="center" prop="source" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:order:remove']"
          >删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['module:orders:query']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="订单流水号" prop="traceNo">
          <el-input v-model="form.traceNo" placeholder="请输入订单流水号" />
        </el-form-item>
        <el-form-item label="业务类型(1：商品订购)">
          <el-select v-model="form.businessType" placeholder="请选择业务类型(1：商品订购)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="商品总费用" prop="goodsPrice">
          <el-input v-model="form.goodsPrice" placeholder="请输入商品总费用" />
        </el-form-item>
        <el-form-item label="配送费用" prop="freightPrice">
          <el-input v-model="form.freightPrice" placeholder="请输入配送费用" />
        </el-form-item>
        <el-form-item label="优惠券减免" prop="couponPrice">
          <el-input v-model="form.couponPrice" placeholder="请输入优惠券减免" />
        </el-form-item>
        <el-form-item label="用户积分减免" prop="integralPrice">
          <el-input v-model="form.integralPrice" placeholder="请输入用户积分减免" />
        </el-form-item>
        <el-form-item label="团购优惠价减免" prop="grouponPrice">
          <el-input v-model="form.grouponPrice" placeholder="请输入团购优惠价减免" />
        </el-form-item>
        <el-form-item label="订单金额(单位：元)， = goods_price + freight_price - coupon_price" prop="orderPrice">
          <el-input v-model="form.orderPrice" placeholder="请输入订单金额(单位：元)， = goods_price + freight_price - coupon_price" />
        </el-form-item>
        <el-form-item label="实付金额(单位：元)， = order_price - integral_price" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入实付金额(单位：元)， = order_price - integral_price" />
        </el-form-item>
        <el-form-item label="支付方式(1：微信小程序)">
          <el-select v-model="form.payType" placeholder="请选择支付方式(1：微信小程序)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付账户" prop="payAccount">
          <el-input v-model="form.payAccount" placeholder="请输入支付账户" />
        </el-form-item>
        <el-form-item label="支付单号" prop="payNo">
          <el-input v-model="form.payNo" placeholder="请输入支付单号" />
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择支付时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收货人姓名" prop="consigneeName">
          <el-input v-model="form.consigneeName" placeholder="请输入收货人姓名" />
        </el-form-item>
        <el-form-item label="收货人手机号" prop="consigneeMobile">
          <el-input v-model="form.consigneeMobile" placeholder="请输入收货人手机号" />
        </el-form-item>
        <el-form-item label="省份" prop="consigneeProvince">
          <el-input v-model="form.consigneeProvince" placeholder="请输入省份" />
        </el-form-item>
        <el-form-item label="城市" prop="consigneeCity">
          <el-input v-model="form.consigneeCity" placeholder="请输入城市" />
        </el-form-item>
        <el-form-item label="收货地址所在区" prop="consigneeArea">
          <el-input v-model="form.consigneeArea" placeholder="请输入收货地址所在区" />
        </el-form-item>
        <el-form-item label="详细地址" prop="consigneeAddress">
          <el-input v-model="form.consigneeAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="业务状态(1：待支付、2：待发货、3：待收货、4：已收货、5：已完成、6：已取消、7：申请退款、8：退款中、9：退款成功、10：退款失败、11：未支付自动取消，不在客户端显示)，初始1">
          <el-radio-group v-model="form.businessStatus">
            <el-radio
              v-for="dict in businessStatusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="买家留言" prop="message">
          <el-input v-model="form.message" placeholder="请输入买家留言" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="物流公司信息(物流公司编码)" prop="logisticsCompany">
          <el-input v-model="form.logisticsCompany" placeholder="请输入物流公司信息(物流公司编码)" />
        </el-form-item>
        <el-form-item label="物流单号" prop="logisticsNumber">
          <el-input v-model="form.logisticsNumber" placeholder="请输入物流单号" />
        </el-form-item>
        <el-form-item label="发货时间" prop="shipTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.shipTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择发货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="配送方式">
          <el-select v-model="form.freightType" placeholder="请选择配送方式">
            <el-option
              v-for="dict in freightTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推广用户" prop="shareUserId">
          <el-input v-model="form.shareUserId" placeholder="请输入推广用户" />
        </el-form-item>
        <el-form-item label="提货码" prop="fetchCode">
          <el-input v-model="form.fetchCode" placeholder="请输入提货码" />
        </el-form-item>
        <el-form-item label="销售信息(销售团长手机号，姓名)" prop="saleInfo">
          <el-input v-model="form.saleInfo" placeholder="请输入销售信息(销售团长手机号，姓名)" />
        </el-form-item>
        <el-form-item label="提货信息(提货店长手机号，姓名)" prop="takeInfo">
          <el-input v-model="form.takeInfo" placeholder="请输入提货信息(提货店长手机号，姓名)" />
        </el-form-item>
        <el-form-item label="提货门店地址" prop="takeAddress">
          <el-input v-model="form.takeAddress" placeholder="请输入提货门店地址" />
        </el-form-item>
        <el-form-item label="是否已读(0：否、1：是),默认0" prop="isRead">
          <el-input v-model="form.isRead" placeholder="请输入是否已读(0：否、1：是),默认0" />
        </el-form-item>
        <el-form-item label="退款来源，当business_status为9时不为空" prop="source">
          <el-input v-model="form.source" placeholder="请输入退款来源，当business_status为9时不为空" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 订单详情对话框 -->
    <el-dialog :visible.sync="openDetail" title="订单详情" width="800">
      <el-form ref="form" :model="form" size="mini" label-position="left">
        <el-form-item label="订单编号">
          <span>{{ form.traceNo }}</span>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-tag v-for="dict in businessStatusOptions" v-if="dict.dictValue == form.businessStatus">{{ dict.dictLabel }}</el-tag>
        </el-form-item>
        <el-form-item label="订单用户">
          <span v-for="user in userList" v-if="user.userId == form.userId">{{ user.nickName }}</span>
        </el-form-item>
        <el-form-item label="用户留言" v-if="form.remark">
          <span>{{ form.remark }}</span>
        </el-form-item>
        <!--<el-form-item label="收货信息" v-if="form.consigneeName">
          <div>收货人：{{ form.consigneeName }}</div>
          <div>手机号：{{ form.consigneeMobile }}</div>
          <div>{{ form.consigneeProvince }} / {{ form.consigneeCity }} / {{ form.consigneeArea }} / {{ form.consigneeAddress }}</div>
        </el-form-item>-->
        <el-form-item label="提货信息">
          <span>{{ form.takeInfo }} / {{ form.takeAddress }}</span>
        </el-form-item>
        <el-form-item label="商品信息">
          <el-table :data="form.carts" size="small" border fit highlight-current-row>
            <el-table-column align="center" label="商品名称" prop="goods.goodsName" />
            <el-table-column align="center" label="货品规格" prop="goods.specifications" />
            <el-table-column align="center" label="货品价格" prop="goods.price" />
            <el-table-column align="center" label="货品数量" prop="count" />
            <el-table-column align="center" label="货品图片" prop="goods.picUrl">
              <template slot-scope="scope">
                <img :src="scope.row.goods.picUrl" width="40">
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="费用信息">
          <span>
            (实际费用){{ form.actualPrice }}元 =
            (商品总价){{ form.goodsPrice }}元 +
            (快递费用){{ form.freightPrice }}元 -
            (优惠减免){{ form.couponPrice }}元 -
            (积分减免){{ form.integralPrice }}元
          </span>
        </el-form-item>
        <el-form-item label="支付信息">
          <span>支付渠道：微信支付</span>
          <span>支付时间：{{ form.payTime }}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDetail = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder } from "@/api/module/order";
import { listUser } from "@/api/module/user";
const statusMap = {
  0: '未付款',
  1: '用户取消',
  2: '系统取消',
  3: '已付款',
  4: '申请退款',
  5: '已退款',
  6: '已发货',
  7: '用户收货',
  8: '系统收货'
}

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 所有用户数据
      userList: [],
      // 是否显示详细数据弹出层
      openDetail: false,
      // 业务状态(1：待支付、2：待发货、3：待收货、4：已收货、5：已完成、6：已取消、7：申请退款、8：退款中、9：退款成功、10：退款失败、11：未支付自动取消，不在客户端显示)，初始1字典
      businessStatusOptions: [],
      // 状态字典
      statusOptions: [],
      // 配送方式字典
      freightTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        traceNo: undefined,
        businessType: undefined,
        goodsPrice: undefined,
        freightPrice: undefined,
        couponPrice: undefined,
        integralPrice: undefined,
        grouponPrice: undefined,
        orderPrice: undefined,
        amount: undefined,
        payType: undefined,
        payAccount: undefined,
        payNo: undefined,
        payTime: undefined,
        consigneeName: undefined,
        consigneeMobile: undefined,
        consigneeProvince: undefined,
        consigneeCity: undefined,
        consigneeArea: undefined,
        consigneeAddress: undefined,
        businessStatus: undefined,
        message: undefined,
        status: undefined,
        logisticsCompany: undefined,
        logisticsNumber: undefined,
        shipTime: undefined,
        freightType: undefined,
        shareUserId: undefined,
        fetchCode: undefined,
        saleInfo: undefined,
        takeInfo: undefined,
        takeAddress: undefined,
        isRead: undefined,
        source: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ],
        traceNo: [
          { required: true, message: "订单流水号不能为空", trigger: "blur" }
        ],
        businessType: [
          { required: true, message: "业务类型(1：商品订购)不能为空", trigger: "blur" }
        ],
        goodsPrice: [
          { required: true, message: "商品总费用不能为空", trigger: "blur" }
        ],
        couponPrice: [
          { required: true, message: "优惠券减免不能为空", trigger: "blur" }
        ],
        integralPrice: [
          { required: true, message: "用户积分减免不能为空", trigger: "blur" }
        ],
        grouponPrice: [
          { required: true, message: "团购优惠价减免不能为空", trigger: "blur" }
        ],
        orderPrice: [
          { required: true, message: "订单金额(单位：元)， = goods_price + freight_price - coupon_price不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "实付金额(单位：元)， = order_price - integral_price不能为空", trigger: "blur" }
        ],
        businessStatus: [
          { required: true, message: "业务状态(1：待支付、2：待发货、3：待收货、4：已收货、5：已完成、6：已取消、7：申请退款、8：退款中、9：退款成功、10：退款失败、11：未支付自动取消，不在客户端显示)，初始1不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        freightType: [
          { required: true, message: "配送方式不能为空", trigger: "blur" }
        ],
        saleInfo: [
          { required: true, message: "销售信息(销售团长手机号，姓名)不能为空", trigger: "blur" }
        ],
        takeInfo: [
          { required: true, message: "提货信息(提货店长手机号，姓名)不能为空", trigger: "blur" }
        ],
        takeAddress: [
          { required: true, message: "提货门店地址不能为空", trigger: "blur" }
        ],
        isRead: [
          { required: true, message: "是否已读(0：否、1：是),默认0不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getUserList();
    this.getTDictDatas("module_business_status").then(response => {
      this.businessStatusOptions = response.data;
    });
    this.getTDictDatas("module_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getTDictDatas("module_freight_type").then(response => {
      this.freightTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询所有用户信息 */
    getUserList() {
      const data = {
        status: 0
      };
      listUser(data).then(response => {
        this.userList = response.rows;
      });
    },
    // 业务状态(1：待支付、2：待发货、3：待收货、4：已收货、5：已完成、6：已取消、7：申请退款、8：退款中、9：退款成功、10：退款失败、11：未支付自动取消，不在客户端显示)，初始1字典翻译
    businessStatusFormat(row, column) {
      return this.selectDictLabel(this.businessStatusOptions, row.businessStatus);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 配送方式字典翻译
    freightTypeFormat(row, column) {
      return this.selectDictLabel(this.freightTypeOptions, row.freightType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: undefined,
        userId: undefined,
        traceNo: undefined,
        businessType: undefined,
        goodsPrice: undefined,
        freightPrice: undefined,
        couponPrice: undefined,
        integralPrice: undefined,
        grouponPrice: undefined,
        orderPrice: undefined,
        amount: undefined,
        payType: undefined,
        payAccount: undefined,
        payNo: undefined,
        payTime: undefined,
        consigneeName: undefined,
        consigneeMobile: undefined,
        consigneeProvince: undefined,
        consigneeCity: undefined,
        consigneeArea: undefined,
        consigneeAddress: undefined,
        businessStatus: "0",
        message: undefined,
        remark: undefined,
        createTime: undefined,
        updateTime: undefined,
        status: "0",
        logisticsCompany: undefined,
        logisticsNumber: undefined,
        shipTime: undefined,
        freightType: undefined,
        shareUserId: undefined,
        fetchCode: undefined,
        saleInfo: undefined,
        takeInfo: undefined,
        takeAddress: undefined,
        isRead: undefined,
        source: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getOrder(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 详细按钮操作 */
    handleDetail(row) {
      this.openDetail = true;
      this.form = row;
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != undefined) {
            updateOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addOrder(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm('是否确认删除订单编号为"' + orderIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(orderIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
